#coding:utf-8
# Create your views here.
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'webtest.web.settings'
from django.contrib.auth.models import User
from django.contrib.auth import authenticate

def create_user(username, password):
    assert username and username.strip() \
        and password and password.strip(), "username or password can not empty"
    assert not User.objects.filter(username=username), "user '%s' already exist" % username
    User.objects.create_user(username, '', password)

def set_password(username, old_password, new_password):
    user = authenticate(username=username, password=old_password)
    assert user, "username or password incorrect"
    user.set_password(new_password)
    user.save()
